package com.itcast;

import com.itcast.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class MybatisDemo {
    public static void main(String[] args) throws Exception {
        //1.加载mybatis核心配置文件 获取sqlsessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory =new SqlSessionFactoryBuilder().build(inputStream);

        //2.获取sqlsession对象 来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //执行sql
        List<User> users = sqlSession.selectList("test.selectAll");

        System.out.println(users);
sqlSession.close();
    }
}
